import numpy as np
from functools import reduce


def ivecs_read(fname):
    a = np.fromfile(fname, dtype='int32')
    d = a[0]
    return a.reshape(-1, d + 1)[:, 1:].copy(), d


def fvecs_read(fname):
    data, d = ivecs_read(fname)
    return data.view('float32').astype(np.float32), d


dataset = 'netflix'

cosine_gnd, dim = ivecs_read("../data/%s_bias/cosine_gnd_idx.ivecs" % dataset)
ip_gnd, dim = ivecs_read("../data/%s_bias/ip_gnd_idx.ivecs" % dataset)
l2_gnd, dim = ivecs_read("../data/%s_bias/l2_gnd_idx.ivecs" % dataset)
norm_gnd, dim = ivecs_read("../data/%s_bias/norm_gnd_idx.ivecs" % dataset)

print(cosine_gnd.shape, ip_gnd.shape, l2_gnd.shape, norm_gnd.shape)
print(cosine_gnd)
print(ip_gnd)
print(l2_gnd)
print(norm_gnd)
